package com.chengwei.ch.busdemo.adapter;

import android.text.Editable;
import android.text.TextWatcher;

//import com.chad.library.adapter.base.BaseQuickAdapter;
//import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chengwei.ch.busdemo.R;
import com.zyl.customkeyboardview.CustomKeyboardEditText;


import java.util.ArrayList;

public class BuyTicketScanInfAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private CustomKeyboardEditText etPassengersName;

    public BuyTicketScanInfAdapter(int layoutResId, ArrayList<String> list) {
        super(layoutResId, list);
    }

    @Override
    protected void convert(BaseViewHolder helper, String s) {
        etPassengersName = helper.getView(R.id.etIdCardTicketBuyInf);
        helper.setText(R.id.etIdCardTicketBuyInf, s);
        //第一步->根据Tag移除掉监听
        if (etPassengersName.getTag() instanceof TextWatcher) {
            etPassengersName.removeTextChangedListener((TextWatcher) etPassengersName.getTag());
        }
        //第二步->set文字
        etPassengersName.setText(s);
        //第三步->添加一个监听
        TextWatcher watcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //用户输入完毕后，处理输入数据，回调给主界面处理
                SaveEditListener listener = (SaveEditListener) mContext;
                listener.saveEdit(s.toString(), helper.getPosition());


            }
        };
        etPassengersName.addTextChangedListener(watcher);
        //第四步->设置一个Tag
        etPassengersName.setTag(watcher);
    }

    public interface SaveEditListener {
        void saveEdit(String name, Integer position);
    }
}
